package cn.edu.tcu.controller.admin;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import cn.edu.tcu.bean.AdminBean;
import cn.edu.tcu.dao.admin.DaoFactory;
import cn.edu.tcu.myutils.MyUtil;

@WebServlet("/AdminInfoEasyUIQueryServlet")
public class AdminInfoEasyUIQueryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 获取客户端request表单数据
		AdminBean adminB = MyUtil.convertRequestParameter2Bean(request, AdminBean.class,null,null);
		MyUtil.logRootLogger.info("转换的Bean："+adminB.toString());
		// 查询数据库，并返回给客户端json对象		
		List<AdminBean> lstAdmins = DaoFactory.getAdminDaoInstance().getAdminInfoByParams(adminB);
		// 组织datagrid需要的数据结构
		Map<String,Object> mapGrid = new HashMap<>();
		mapGrid.put("total", 12);  
		mapGrid.put("rows", lstAdmins);  
		// 将查询结果集转换为json对象
		String json = JSON.toJSONStringWithDateFormat(mapGrid, "yyyy-MM-dd HH:mm:ss");
		//response.setContentType("text/html;charset=utf-8");
		response.getWriter().write(json);
		response.getWriter().flush();
		response.getWriter().close();
	}

}
